package com.hq.fxh.No2_BBS.Activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import com.hq.fxh.R;
import com.hq.fxh.Utils.DensityUtils;
import com.hq.fxh.Utils.GlideUtils;
import com.hq.fxh.Utils.LogUtils;
import com.hq.fxh.Utils.SystemUtils;

public class TestImageActivity extends AppCompatActivity implements View.OnClickListener {
    protected Button btn1;
    protected Button btn2;
    protected Button btn3;
    protected Button btn4;
    protected ImageView testImage;
    String url1 = "http://imgs.ledianduo.com/app/post/2017/8/28/20170828173340636395384206607809.png";
    String url2 = "http://imgs.ledianduo.com/app/post/2017/8/28/20170828173323636395384030199043.png";
    String url3 = "http://imgs.ledianduo.com/app/post/2017/8/28/20170828171521636395373217769606.png";
    String url4 = "http://imgs.ledianduo.com/app/post/2017/8/28/20170828153150636395311106498692.png";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.activity_test_image);

        initView();

    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn1) {
            GlideUtils.loadImageView(this, url1, testImage);

        } else if (view.getId() == R.id.btn2) {
            GlideUtils.loadImageView(this, url2, testImage);


        } else if (view.getId() == R.id.btn3) {
            GlideUtils.loadImageView(this, url3, testImage);


        } else if (view.getId() == R.id.btn4) {
            GlideUtils.loadImageView(this, url4, testImage);


        }
        ViewGroup.LayoutParams layoutParams = testImage.getLayoutParams();
        LogUtils.e("宽度="+layoutParams.width+"   高度="+layoutParams.height);

    }

    private void initView() {
        btn1 = (Button) findViewById(R.id.btn1);
        btn1.setOnClickListener(TestImageActivity.this);
        btn2 = (Button) findViewById(R.id.btn2);
        btn2.setOnClickListener(TestImageActivity.this);
        btn3 = (Button) findViewById(R.id.btn3);
        btn3.setOnClickListener(TestImageActivity.this);
        btn4 = (Button) findViewById(R.id.btn4);
        btn4.setOnClickListener(TestImageActivity.this);
        testImage = (ImageView) findViewById(R.id.testImage);

        int windowWidth = SystemUtils.getWindowWidth(this);
        testImage.setAdjustViewBounds(true);
        testImage.setMaxWidth(windowWidth - DensityUtils.dip2px(this, 30));
     /*   ViewGroup.LayoutParams layoutParams = testImage.getLayoutParams();
        layoutParams.width=windowWidth;
        testImage.setLayoutParams(layoutParams);*/
        testImage.setMinimumWidth(DensityUtils.dip2px(this, 165));
        testImage.setMinimumHeight(DensityUtils.dip2px(this, 150));
        int maxHeight = DensityUtils.dip2px(this, 250);
        testImage.setMaxHeight(maxHeight);

        LogUtils.e("宽度" + windowWidth);
    }
}
